﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Rights_GetAccessPermission_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Rights_GetAccessPermission_V2];
GO
CREATE PROCEDURE [dbo].[sproc_Rights_GetAccessPermission_V2]
    @Class_ID int,
    @Username nvarchar(50),
    @Act_ID int,
    @ReturnValue int output
/*

========================================================
功能:得到用户@Username对对象@Class_ID是否又@Act_ID权
参数:
    @Class_id int        :    组（类）ID
备注:可以优化
========================================================

*/
AS
BEGIN
SET NOCOUNT ON

    DECLARE @staffId int;
    DECLARE @allowAccess bit;

    -- Get the id of the staff
    SELECT @staffId = Staff_ID FROM dbo.UDS_Staff WHERE Staff_Name = @Username;
    IF ( @@ROWCOUNT <> 1 )
    BEGIN
        RAISERROR(N'The specified user "%s" does not exist.', 16, 1, @Username);
        RETURN -1;
    END
    
    SELECT @allowAccess = [dbo].[fn_has_access_permission] ( @Class_ID, @staffID, @Act_ID );
    IF ( @allowAccess = 1 )
        GOTO HAS_PERMISSION;

    -- The user does not have the requested permission.
    SET @ReturnValue = 0;
    RETURN 0;

HAS_PERMISSION:
    SET @ReturnValue = 1;
    RETURN 1;

END
GO